﻿app.controller("encabezadoController", function ($scope, encabezadoService, $window) {

    $scope.hola = function () {
        console.log($scope.Periodo);
    }
    $scope.list = [];

    $scope.lis = function () {
        encabezadoService.getList().then(function (results) {
            $scope.list = results.data;
        }, function (error) {
            console.log(error.data.message);
        });
    }

    $scope.getById = function (encabezado) {
        $scope.encabezado = encabezado;
        $scope.formVisibility = true;
        console.log($scope.formVisibility)
    };

    $scope.save = function () {
        if ($scope.encabezado.Id) {
            encabezadoService.update({ Id: "" }, $scope.encabezado).then(function (results) {
                console.log(results.data);
                $scope.lis();
            }, function (error) {
                console.log(error.data.message);
            });
        } else {
            encabezadoService.create($scope.encabezado).then(function (results) {
                console.log(results.data);
                $scope.lis();
            }, function (error) {
                console.log(error.data.message);
            });
        }
        $scope.formVisibility = false;
        console.log($scope.formVisibility)
    }
    $scope.delete = function (encabezado) {
        if ($window.confirm('Confirm delete')) {
            encabezadoService.delete({ Id: encabezado.Id }).then(function (results) {
                console.log(results.data);
                $scope.lis();
            }, function (error) {
                console.log(error.data.message);
            });
        }
    }
    $scope.lis();
    $scope.formVisibility = false;
    $scope.ShowForm = function () {
        $scope.formVisibility = true;
        console.log($scope.formVisibility)
    }
    $scope.cancel = function () {
        $scope.formVisibility = false;
        console.log($scope.formVisibility)
    }

});